using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
	/// <summary>
	/// Strongly-typed collection for the NewsSection class.
	/// </summary>
	[Serializable]
	public partial class NewsSectionCollection : ActiveList<NewsSection, NewsSectionCollection> 
	{	   
		public NewsSectionCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the NewsSection table.
	/// </summary>
	[Serializable]
	public partial class NewsSection : ActiveRecord<NewsSection>
	{
		#region .ctors and Default Settings
		
		public NewsSection()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public NewsSection(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public NewsSection(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public NewsSection(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("NewsSection", TableType.Table, DataService.GetInstance("Adex"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarSectionID = new TableSchema.TableColumn(schema);
				colvarSectionID.ColumnName = "SectionID";
				colvarSectionID.DataType = DbType.Int32;
				colvarSectionID.MaxLength = 0;
				colvarSectionID.AutoIncrement = true;
				colvarSectionID.IsNullable = false;
				colvarSectionID.IsPrimaryKey = false;
				colvarSectionID.IsForeignKey = false;
				colvarSectionID.IsReadOnly = false;
				colvarSectionID.DefaultSetting = @"";
				colvarSectionID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSectionID);
				
				TableSchema.TableColumn colvarSectionCode = new TableSchema.TableColumn(schema);
				colvarSectionCode.ColumnName = "SectionCode";
				colvarSectionCode.DataType = DbType.Int32;
				colvarSectionCode.MaxLength = 0;
				colvarSectionCode.AutoIncrement = false;
				colvarSectionCode.IsNullable = false;
				colvarSectionCode.IsPrimaryKey = true;
				colvarSectionCode.IsForeignKey = false;
				colvarSectionCode.IsReadOnly = false;
				colvarSectionCode.DefaultSetting = @"";
				colvarSectionCode.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSectionCode);
				
				TableSchema.TableColumn colvarSectionName = new TableSchema.TableColumn(schema);
				colvarSectionName.ColumnName = "SectionName";
				colvarSectionName.DataType = DbType.String;
				colvarSectionName.MaxLength = 300;
				colvarSectionName.AutoIncrement = false;
				colvarSectionName.IsNullable = true;
				colvarSectionName.IsPrimaryKey = false;
				colvarSectionName.IsForeignKey = false;
				colvarSectionName.IsReadOnly = false;
				colvarSectionName.DefaultSetting = @"";
				colvarSectionName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSectionName);
				
				TableSchema.TableColumn colvarDateAdded = new TableSchema.TableColumn(schema);
				colvarDateAdded.ColumnName = "DateAdded";
				colvarDateAdded.DataType = DbType.DateTime;
				colvarDateAdded.MaxLength = 0;
				colvarDateAdded.AutoIncrement = false;
				colvarDateAdded.IsNullable = false;
				colvarDateAdded.IsPrimaryKey = false;
				colvarDateAdded.IsForeignKey = false;
				colvarDateAdded.IsReadOnly = false;
				colvarDateAdded.DefaultSetting = @"";
				colvarDateAdded.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateAdded);
				
				TableSchema.TableColumn colvarDateModified = new TableSchema.TableColumn(schema);
				colvarDateModified.ColumnName = "DateModified";
				colvarDateModified.DataType = DbType.DateTime;
				colvarDateModified.MaxLength = 0;
				colvarDateModified.AutoIncrement = false;
				colvarDateModified.IsNullable = false;
				colvarDateModified.IsPrimaryKey = false;
				colvarDateModified.IsForeignKey = false;
				colvarDateModified.IsReadOnly = false;
				colvarDateModified.DefaultSetting = @"";
				colvarDateModified.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateModified);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Adex"].AddSchema("NewsSection",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("SectionID")]
		public int SectionID 
		{
			get { return GetColumnValue<int>("SectionID"); }

			set { SetColumnValue("SectionID", value); }

		}

		  
		[XmlAttribute("SectionCode")]
		public int SectionCode 
		{
			get { return GetColumnValue<int>("SectionCode"); }

			set { SetColumnValue("SectionCode", value); }

		}

		  
		[XmlAttribute("SectionName")]
		public string SectionName 
		{
			get { return GetColumnValue<string>("SectionName"); }

			set { SetColumnValue("SectionName", value); }

		}

		  
		[XmlAttribute("DateAdded")]
		public DateTime DateAdded 
		{
			get { return GetColumnValue<DateTime>("DateAdded"); }

			set { SetColumnValue("DateAdded", value); }

		}

		  
		[XmlAttribute("DateModified")]
		public DateTime DateModified 
		{
			get { return GetColumnValue<DateTime>("DateModified"); }

			set { SetColumnValue("DateModified", value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varSectionCode,string varSectionName,DateTime varDateAdded,DateTime varDateModified)
		{
			NewsSection item = new NewsSection();
			
			item.SectionCode = varSectionCode;
			
			item.SectionName = varSectionName;
			
			item.DateAdded = varDateAdded;
			
			item.DateModified = varDateModified;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varSectionID,int varSectionCode,string varSectionName,DateTime varDateAdded,DateTime varDateModified)
		{
			NewsSection item = new NewsSection();
			
				item.SectionID = varSectionID;
				
				item.SectionCode = varSectionCode;
				
				item.SectionName = varSectionName;
				
				item.DateAdded = varDateAdded;
				
				item.DateModified = varDateModified;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string SectionID = @"SectionID";
			 public static string SectionCode = @"SectionCode";
			 public static string SectionName = @"SectionName";
			 public static string DateAdded = @"DateAdded";
			 public static string DateModified = @"DateModified";
						
		}

		#endregion
	}

}

